import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: []
}
const mutations = {
  // 拼接静态和动态路由
  setRoutes(state, routes) {
    state.routes = [...constantRoutes, ...routes]
    console.log(11, state.routes)
  }
}
const actions = {
  filterRoute(store, menus) {
    // console.log(menus)
    // console.log(asyncRoutes)
    const routes = asyncRoutes.filter(route => menus.includes(route.name))
    store.commit('setRoutes', routes)
    // console.log(routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
